import 'package:get/get.dart';
import 'package:getxdemo/get/getx_controller_inject.dart';
import 'package:getxdemo/utils/toast_util.dart';

import '../../../route/routers.dart';

class LoginLogic extends BaseGetController {
  String userCount = "";
  String passWord = "";

  bool get inputEnable => userCount.isNotEmpty && passWord.isNotEmpty;

  void login() {
    if (userCount.isEmpty || passWord.isEmpty) {
      return;
    }
    if (userCount.length < 6) {
      ToastUtils.show("用户名至少六位！");
      return;
    }
    if (passWord.length < 6) {
      ToastUtils.show("密码至少六位！");
      return;
    }

    request.login(userCount, passWord, (data) {
      ToastUtils.show("登录成功！");
      Get.offAllNamed(Routes.homePage);
    }, (code, message) {
      ToastUtils.show(message);
    });
  }
}
